//
//  RCActivityOrderViewController.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-28.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCActivityOrderViewController.h"
#import "UIColor-Expanded.h"
#import "CommonDefines.h"
#import "NSString+NSString_Ex_.h"
#import "NSArray+EX.h"
#import "AppDelegate.h"
#import "GloableEngineService.h"
#import "RCFeedbackDataModel.h"
#import "RCMerchantOrderDataModel.h"
#import "IManager+ModuleMerchantOrder.h"
#import "TTTAttributedLabel.h"
#import "NSAttributedString+LVAddition.h"

#define kFormImageFile           @"image_merchant_commit_form.png"
#define kLineImageFile           @"image_order_line.png"

#define kOrderForm1ImageFile     @"image_activity_order_form1.png"
#define kOrderForm2ImageFile     @"image_activity_order_form2.png"
#define kOrderForm3ImageFile     @"image_activity_order_form3.png"
#define kButtonImageFile         @"login_btn.png"

#define kDatePickerCancelButton                @"image_tinyNote_edit_datePicker_cancel.png"
#define kDatePickerCancelPressed               @"image_tinyNote_edit_datePicker_cancel_pressed.png"
#define kDatePickerDoneButton                  @"image_tinyNote_edit_datePicker_done.png"
#define kDatePickerDonePressed                 @"image_tinyNote_edit_datePicker_done_pressed.png"
#define kDatePickerBGImageFile                 @"image_tinyNote_edit_datePicker_timebar.png"

#define kDatePickerBGFrame                     CGRectMake(0,UIScreenHeight-64-256,320,256)
#define kDatePickerButtonBGFrame               CGRectMake(0,0,320,40)
#define kDatePickerCancelFrame                 CGRectMake(20,5,50,30)
#define kDatePickerDoneFrame                   CGRectMake(250,5,50,30)
#define kDatePickerFrame                       CGRectMake(0,40,320,216)
#define kDatePickerUpperFrame                  CGRectMake(0,0,320,UIScreenHeight-64-256)

@interface RCActivityOrderViewController ()

@property(nonatomic,copy)  NSString    *activityID;
@property(nonatomic,copy)  NSString    *shopID;
@property(nonatomic,retain)UIScrollView *contentView;
@property(nonatomic,retain)UITextField *nameTextField;
@property(nonatomic,retain)UITextField *phoneTextField;

@property(nonatomic,retain)UIView         *malePickerBGView;
@property(nonatomic,retain)UIImageView    *malePickerButtonBGView;
@property(nonatomic,retain)UIButton       *malePickerCancelButton;
@property(nonatomic,retain)UIButton       *malePickerDoneButton;
@property(nonatomic,retain)UIButton       *malePickerUpperButton;
@property(nonatomic,retain)UIPickerView   *malePickerView;
@property(nonatomic,copy)  NSString       *maleString;


@property(nonatomic,retain)UIView         *peoplePickerBGView;
@property(nonatomic,retain)UIImageView    *peoplePickerButtonBGView;
@property(nonatomic,retain)UIButton       *peoplePickerCancelButton;
@property(nonatomic,retain)UIButton       *peoplePickerDoneButton;
@property(nonatomic,retain)UIButton       *peoplePickerUpperButton;
@property(nonatomic,retain)UIPickerView   *peopleNumberPickerView;
@property(nonatomic,copy)  NSString       *peopleString;


@property(nonatomic,retain)UIView         *typePickerBGView;
@property(nonatomic,retain)UIImageView    *typePickerButtonBGView;
@property(nonatomic,retain)UIButton       *typePickerCancelButton;
@property(nonatomic,retain)UIButton       *typePickerDoneButton;
@property(nonatomic,retain)UIButton       *typePickerUpperButton;
@property(nonatomic,retain)UIPickerView   *typePickerView;
@property(nonatomic,copy)  NSString       *typeString;


@property(nonatomic,retain)UILabel      *maleLabel;
@property(nonatomic,retain)UILabel      *peopleNumberLabel;
@property(nonatomic,retain)UILabel      *dateLabel;
@property(nonatomic,retain)UILabel      *timeLabel;
@property(nonatomic,retain)UILabel      *typeLabel;
@property(nonatomic,retain)NSMutableArray *maleArray;
@property(nonatomic,retain)NSMutableArray *peopleNumberArray;

@property(nonatomic,retain)UIView         *datePickerBGView;
@property(nonatomic,retain)UIDatePicker   *datePicker;
@property(nonatomic,retain)UIImageView    *datePickerButtonBGView;
@property(nonatomic,retain)UIButton       *datePickerCancelButton;
@property(nonatomic,retain)UIButton       *datePickerDoneButton;
@property(nonatomic,retain)UIButton       *datePickerUpperButton;

@property(nonatomic,assign)CGFloat        currentContentOffsetY;

@property(nonatomic,retain)UITextView     *messageTextView;
@property(nonatomic,assign)TextViewType   textViewType;

@property(nonatomic,retain)UIButton *commitButton;
@property(nonatomic,retain)MBProgressHUDEx *progressHub;
@property(nonatomic,assign)int64_t requestID;
@property(nonatomic,assign)int64_t orderInfoRequestID;
@property(nonatomic,retain)RCMerchantOrderDataModel *orderInfoDataModel;

@end

@implementation RCActivityOrderViewController

@synthesize activityID = _activityID;
@synthesize shopID = _shopID;
@synthesize contentView = _contentView;
@synthesize nameTextField = _nameTextField;
@synthesize phoneTextField = _phoneTextField;

@synthesize malePickerBGView = _malePickerBGView;
@synthesize malePickerCancelButton = _malePickerCancelButton;
@synthesize malePickerDoneButton = _malePickerDoneButton;
@synthesize malePickerUpperButton = _malePickerUpperButton;
@synthesize malePickerButtonBGView = _malePickerButtonBGView;
@synthesize malePickerView = _malePickerView;
@synthesize maleString = _maleString;


@synthesize peopleNumberPickerView = _peopleNumberPickerView;
@synthesize peoplePickerBGView = _peoplePickerBGView;
@synthesize peoplePickerButtonBGView = _peoplePickerButtonBGView;
@synthesize peoplePickerCancelButton = _peoplePickerCancelButton;
@synthesize peoplePickerDoneButton = _peoplePickerDoneButton;
@synthesize peoplePickerUpperButton = _peoplePickerUpperButton;
@synthesize peopleString = _peopleString;

@synthesize typePickerView = _typePickerView;
@synthesize typePickerBGView = _typePickerBGView;
@synthesize typePickerButtonBGView = _typePickerButtonBGView;
@synthesize typePickerCancelButton = _typePickerCancelButton;
@synthesize typePickerDoneButton = _typePickerDoneButton;
@synthesize typePickerUpperButton = _typePickerUpperButton;
@synthesize typeString = _typeString;

@synthesize maleLabel = _maleLabel;
@synthesize peopleNumberLabel = _peopleNumberLabel;
@synthesize dateLabel = _dateLabel;
@synthesize timeLabel = _timeLabel;
@synthesize typeLabel = _typeLabel;
@synthesize maleArray = _maleArray;
@synthesize peopleNumberArray = _peopleNumberArray;
@synthesize datePicker = _datePicker;
@synthesize datePickerButtonBGView = _datePickerButtonBGView;
@synthesize datePickerCancelButton = _datePickerCancelButton;
@synthesize datePickerDoneButton = _datePickerDoneButton;
@synthesize datePickerUpperButton = _datePickerUpperButton;
@synthesize datePickerBGView = _datePickerBGView;

@synthesize messageTextView = _messageTextView;
@synthesize commitButton = _commitButton;
@synthesize progressHub = _progressHub;
@synthesize requestID = _requestID;
@synthesize orderInfoRequestID = _orderInfoRequestID;
@synthesize orderInfoDataModel = _orderInfoDataModel;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(id)initWithShopID:(NSString *)shopID{
    self = [super init];
    if (self) {
        self.shopID = shopID;
        self.maleArray = [NSMutableArray arrayWithObjects:@"男士",@"女士", nil];
        self.peopleNumberArray = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"20+", nil];
        self.peopleString = @"2";
        self.maleString = @"男士";
        [self initKeyBoard];
    }
    return self;
}

-(void)initKeyBoard{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
    self.progressHub.delegate = nil;
    self.progressHub = nil;
    self.activityID = nil;
    self.shopID = nil;
    self.commitButton = nil;
    self.messageTextView = nil;
    self.nameTextField = nil;
    self.phoneTextField = nil;
    
    self.malePickerView = nil;
    self.malePickerUpperButton = nil;
    self.malePickerCancelButton = nil;
    self.malePickerDoneButton = nil;
    self.malePickerButtonBGView = nil;
    self.malePickerBGView = nil;
    self.maleString = nil;
    
    self.peopleNumberPickerView = nil;
    self.peoplePickerUpperButton = nil;
    self.peoplePickerCancelButton = nil;
    self.peoplePickerDoneButton = nil;
    self.peoplePickerButtonBGView = nil;
    self.peoplePickerBGView = nil;
    self.peopleString = nil;
    
    self.typePickerView = nil;
    self.typePickerUpperButton = nil;
    self.typePickerCancelButton = nil;
    self.typePickerDoneButton = nil;
    self.typePickerButtonBGView = nil;
    self.typePickerBGView = nil;
    self.typeString = nil;
    
    self.peopleNumberLabel = nil;
    self.datePicker = nil;
    self.maleLabel = nil;
    self.dateLabel = nil;
    self.timeLabel = nil;
    self.typeLabel = nil;
    self.maleArray = nil;
    self.peopleNumberArray = nil;
    self.datePickerButtonBGView = nil;
    self.datePickerCancelButton = nil;
    self.datePickerDoneButton = nil;
    self.datePickerUpperButton = nil;
    self.datePickerBGView = nil;
    self.orderInfoDataModel = nil;
    self.contentView = nil;
    [super dealloc];
}

-(void)loadView{
    [super loadView];
    self.titleLabelText = @"在线预订";
    self.navigationItem.titleView = [self createTitleView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self requestData];
    
    
}

-(void)requestData{
    _progressHub = [[MBProgressHUDEx alloc] initWithView:self.view
                                               TopHeight:0
                                        withBottomHeight:0
                                           withLeftWidth:0
                                          withRightWidth:0
                                    withExclusiveObjects:nil];
    _progressHub.delegate = self;
    _progressHub.labelText = @"加载中...";
    [self.view addSubview:_progressHub];
    [self.view bringSubviewToFront:_progressHub];
    [_progressHub show:YES];
    _orderInfoRequestID = [[IManager sharedInstance]requestMerchantOrderInfo:self.shopID WithDelegate:self];
}

-(void)customizeView{
    
    _contentView = [[UIScrollView alloc]initWithFrame:self.viewContainer.bounds];
    _contentView.backgroundColor = [UIColor clearColor];
    
    UILabel *discountWordLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, 15, 200, 12)];
    discountWordLabel.backgroundColor = [UIColor clearColor];
    discountWordLabel.textColor = [UIColor colorWithHex:0xff707070];
    discountWordLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    discountWordLabel.text = @"预订此订单享受";
    [_contentView addSubview:discountWordLabel];
    [discountWordLabel release];
    
    TTTAttributedLabel *discountLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(13, 31, 293, 15)];
    discountLabel.backgroundColor = [UIColor clearColor];
    discountLabel.textColor = [UIColor colorWithHex:0xffff7600];
    discountLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:15];
    discountLabel.leading = 6;
    discountLabel.numberOfLines = 0;
    discountLabel.text = self.orderInfoDataModel.orderServer;
    
    CGSize size = [discountLabel.attributedText sizeWithConstrainedToSize:CGSizeMake(293, 2000) Leading:6];
    discountLabel.frame = CGRectMake(13, 31, 293, size.height);
    [_contentView addSubview:discountLabel];
    [discountLabel release];
    
    CGFloat height = CGRectGetMaxY(discountLabel.frame);
    
    height +=8;
    
    UIImageView *discountLineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, height, 320, 1)];
    discountLineImageView.backgroundColor = [UIColor clearColor];
    [discountLineImageView setImage:[UIImage imageNamed:kLineImageFile]];
    [_contentView addSubview:discountLineImageView];
    [discountLineImageView release];
    height +=1;
    
    
    height +=11;
    UILabel *shopNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, height, 300, 14)];
    shopNameLabel.backgroundColor = [UIColor clearColor];
    shopNameLabel.textColor = [UIColor colorWithHex:0xff505050];
    shopNameLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    shopNameLabel.text = [NSString stringWithFormat:@"商家名称： %@ ",self.orderInfoDataModel.shopName];
    CGSize shopNameSize = [shopNameLabel.text sizeWithFont:shopNameLabel.font constrainedToSize:CGSizeMake(300, 20)];
    shopNameLabel.frame = CGRectMake(13, height, shopNameSize.width, 14);
    [_contentView addSubview:shopNameLabel];
    [shopNameLabel release];
    height+=14;
    
    height+=2;
    UIImageView *shopNameLineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(80, height, shopNameSize.width+13-80+5, 1)];
    shopNameLineImageView.backgroundColor = [UIColor clearColor];
    [shopNameLineImageView setImage:[UIImage imageNamed:kLineImageFile]];
    [_contentView addSubview:shopNameLineImageView];
    [shopNameLineImageView release];
    height+=1;
    
    
    height+=15;
    UILabel *orderLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, height, 200, 12)];
    orderLabel.backgroundColor = [UIColor clearColor];
    orderLabel.textColor = [UIColor colorWithHex:0xff505050];
    orderLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    orderLabel.text = @"预订信息";
    [_contentView addSubview:orderLabel];
    [orderLabel release];
    height+=12;
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDate *currenDay = [NSDate date];
    NSDateComponents *currentComponent = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSCalendarCalendarUnit| NSWeekOfMonthCalendarUnit fromDate:currenDay];
    NSString *weekString = [self getWeekDayStringWithNumber:[currentComponent weekday]];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString = [formatter stringFromDate:currenDay];
    [formatter setDateFormat:@"HH:mm"];
    NSString *timeString = [formatter stringFromDate:currenDay];
    [formatter release];
    
    height+=11;
    UIButton *dateTextFiledImageView = [[UIButton alloc]initWithFrame:CGRectMake(13, height, 186, 40)];
    dateTextFiledImageView.backgroundColor = [UIColor clearColor];
    [dateTextFiledImageView setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kOrderForm2ImageFile ofType:nil]] forState:UIControlStateNormal];
    [dateTextFiledImageView addTarget:self action:@selector(dateTextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    _dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 12, 140, 16)];
    _dateLabel.backgroundColor = [UIColor clearColor];
    _dateLabel.textColor = [UIColor colorWithHex:0xff4a4a4a];
    _dateLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    
    _dateLabel.text = [NSString stringWithFormat:@"%@  %@",dateString,weekString];
    [dateTextFiledImageView addSubview:_dateLabel];
    [_contentView addSubview:dateTextFiledImageView];
    [dateTextFiledImageView release];
    
    
    
    UIButton *timeTextFiledImageView = [[UIButton alloc]initWithFrame:CGRectMake(210, height, 96, 40)];
    timeTextFiledImageView.backgroundColor = [UIColor clearColor];
    [timeTextFiledImageView setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kOrderForm3ImageFile ofType:nil]] forState:UIControlStateNormal];
    [timeTextFiledImageView addTarget:self action:@selector(dateTextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 12, 70, 16)];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.textColor = [UIColor colorWithHex:0xff4a4a4a];
    _timeLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    
    _timeLabel.text = timeString;
    [timeTextFiledImageView addSubview:_timeLabel];
    [_contentView addSubview:timeTextFiledImageView];
    [timeTextFiledImageView release];
    height+=40;
    
    
    height+=11;
    UIButton *peopleTextFiledImageView = [[UIButton alloc]initWithFrame:CGRectMake(13, height, 293, 40)];
    peopleTextFiledImageView.backgroundColor = [UIColor clearColor];
    [peopleTextFiledImageView setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kOrderForm1ImageFile ofType:nil]] forState:UIControlStateNormal];
    [peopleTextFiledImageView addTarget:self action:@selector(peopleTextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *peopleOrderLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 12, 100, 16)];
    peopleOrderLabel.backgroundColor = [UIColor clearColor];
    peopleOrderLabel.textColor = [UIColor colorWithHex:0xff4a4a4a];
    peopleOrderLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    peopleOrderLabel.text = @"人数";
    [peopleTextFiledImageView addSubview:peopleOrderLabel];
    [peopleOrderLabel release];
    
    _peopleNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 12, 130, 16)];
    _peopleNumberLabel.backgroundColor = [UIColor clearColor];
    _peopleNumberLabel.textColor = [UIColor colorWithHex:0xff4a4a4a];
    _peopleNumberLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    _peopleNumberLabel.textAlignment = UITextAlignmentRight;
    _peopleNumberLabel.text = @"2";
    [peopleTextFiledImageView addSubview:_peopleNumberLabel];
    [_contentView addSubview:peopleTextFiledImageView];
    [peopleTextFiledImageView release];
    height+=40;
    
    
    _peoplePickerBGView = [[UIView alloc]initWithFrame:CGRectMake(0, UIScreenHeight-64-190, 320, 190)];
    _peoplePickerBGView.backgroundColor = [UIColor whiteColor];
    [self.viewContainer addSubview:_peoplePickerBGView];
    
    _peoplePickerUpperButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, UIScreenHeight-64-190)];
    _peoplePickerUpperButton.backgroundColor = [UIColor clearColor];
    [_peoplePickerUpperButton addTarget:self action:@selector(peoplePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    _peoplePickerUpperButton.hidden = YES;
    [self.viewContainer addSubview:_peoplePickerUpperButton];
    
    _peoplePickerButtonBGView = [[UIImageView alloc]initWithFrame:kDatePickerButtonBGFrame];
    [_peoplePickerButtonBGView setImage:[UIImage imageNamed:kDatePickerBGImageFile]];
    _peoplePickerButtonBGView.userInteractionEnabled = YES;
    [_peoplePickerBGView addSubview:_peoplePickerButtonBGView];
    
    _peoplePickerCancelButton = [[UIButton alloc]initWithFrame:kDatePickerCancelFrame];
    [_peoplePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelButton] forState:UIControlStateNormal];
    [_peoplePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelPressed] forState:UIControlStateSelected];
    [_peoplePickerCancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [_peoplePickerCancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _peoplePickerCancelButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_peoplePickerCancelButton addTarget:self action:@selector(peoplePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_peoplePickerButtonBGView addSubview:_peoplePickerCancelButton];
    
    
    _peoplePickerDoneButton = [[UIButton alloc]initWithFrame:kDatePickerDoneFrame];
    [_peoplePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDoneButton] forState:UIControlStateNormal];
    [_peoplePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDonePressed] forState:UIControlStateSelected];
    [_peoplePickerDoneButton setTitle:@"完成" forState:UIControlStateNormal];
    [_peoplePickerDoneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _peoplePickerDoneButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_peoplePickerDoneButton addTarget:self action:@selector(peoplePickerDoneButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_peoplePickerButtonBGView addSubview:_peoplePickerDoneButton];
    _peopleNumberPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, 320, 150)];
    _peopleNumberPickerView.tag = 102;
    _peopleNumberPickerView.delegate = self;
    _peopleNumberPickerView.dataSource = self;
    _peopleNumberPickerView.showsSelectionIndicator = YES;
    
    [_peoplePickerBGView addSubview:_peopleNumberPickerView];
    
    _peoplePickerBGView.hidden = YES;
    
    
    if (self.orderInfoDataModel.typeArray != nil && [self.orderInfoDataModel.typeArray count] > 0) {
        
        height +=16;
        
        UILabel *typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, height, 100, 12)];
        typeLabel.backgroundColor = [UIColor clearColor];
        typeLabel.textColor = [UIColor colorWithHex:0xff505050];
        typeLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
        typeLabel.text = @"类型";
        [_contentView addSubview:typeLabel];
        [typeLabel release];
        
        
        UIButton *typeTextFiledImageView = [[UIButton alloc]initWithFrame:CGRectMake(13, height, 186, 40)];
        typeTextFiledImageView.backgroundColor = [UIColor clearColor];
        [typeTextFiledImageView setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kOrderForm2ImageFile ofType:nil]] forState:UIControlStateNormal];
        [typeTextFiledImageView addTarget:self action:@selector(typeTextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        _typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 12, 140, 16)];
        _typeLabel.backgroundColor = [UIColor clearColor];
        _typeLabel.textColor = [UIColor colorWithHex:0xff4a4a4a];
        _typeLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
        
        NSString *typeString = [self.orderInfoDataModel.typeArray safeObjectAtIndex:0];
        _typeLabel.text = typeString;
        [typeTextFiledImageView addSubview:_typeLabel];
        [_contentView addSubview:typeTextFiledImageView];
        [typeTextFiledImageView release];
        
        height +=40;
        
        
        _typePickerBGView = [[UIView alloc]initWithFrame:CGRectMake(0, UIScreenHeight-64-190, 320, 190)];
        _typePickerBGView.backgroundColor = [UIColor whiteColor];
        [self.viewContainer addSubview:_typePickerBGView];
        
        _typePickerUpperButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, UIScreenHeight-64-190)];
        _typePickerUpperButton.backgroundColor = [UIColor clearColor];
        [_typePickerUpperButton addTarget:self action:@selector(typePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
        _typePickerUpperButton.hidden = YES;
        [self.viewContainer addSubview:_typePickerUpperButton];
        
        _typePickerButtonBGView = [[UIImageView alloc]initWithFrame:kDatePickerButtonBGFrame];
        [_typePickerButtonBGView setImage:[UIImage imageNamed:kDatePickerBGImageFile]];
        _typePickerButtonBGView.userInteractionEnabled = YES;
        [_typePickerBGView addSubview:_typePickerButtonBGView];
        
        _typePickerCancelButton = [[UIButton alloc]initWithFrame:kDatePickerCancelFrame];
        [_typePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelButton] forState:UIControlStateNormal];
        [_typePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelPressed] forState:UIControlStateSelected];
        [_typePickerCancelButton setTitle:@"取消" forState:UIControlStateNormal];
        [_typePickerCancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _typePickerCancelButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_typePickerCancelButton addTarget:self action:@selector(typePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
        [_typePickerButtonBGView addSubview:_typePickerCancelButton];
        
        
        _typePickerDoneButton = [[UIButton alloc]initWithFrame:kDatePickerDoneFrame];
        [_typePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDoneButton] forState:UIControlStateNormal];
        [_typePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDonePressed] forState:UIControlStateSelected];
        [_typePickerDoneButton setTitle:@"完成" forState:UIControlStateNormal];
        [_typePickerDoneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _typePickerDoneButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_typePickerDoneButton addTarget:self action:@selector(typePickerDoneButtonClicked) forControlEvents:UIControlEventTouchUpInside];
        [_typePickerButtonBGView addSubview:_typePickerDoneButton];
        _typePickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, 320, 150)];
        _typePickerView.tag = 103;
        _typePickerView.delegate = self;
        _typePickerView.dataSource = self;
        _typePickerView.showsSelectionIndicator = YES;
        [_typePickerBGView addSubview:_typePickerView];
        
        _typePickerBGView.hidden = YES;
        
    }
    
    height +=19;
    UIImageView *typeLineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, height, 320, 1)];
    typeLineImageView.backgroundColor = [UIColor clearColor];
    [typeLineImageView setImage:[UIImage imageNamed:kLineImageFile]];
    [_contentView addSubview:typeLineImageView];
    [typeLineImageView release];
    
    height +=1;
    
    
    height +=19;
    UILabel *contactLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, height, 200, 12)];
    contactLabel.backgroundColor = [UIColor clearColor];
    contactLabel.textColor = [UIColor colorWithHex:0xff505050];
    contactLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    contactLabel.text = @"预约人联系方式";
    [_contentView addSubview:contactLabel];
    [contactLabel release];
    height +=12;
    
    
    height +=11;
    UIImage *textFiledImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kFormImageFile ofType:nil]];
    textFiledImage = [textFiledImage resizableImageWithCapInsets:UIEdgeInsetsMake(3, 3, 3, 3)];
    
    UIImageView *nameTextFiledImageView = [[UIImageView alloc]initWithFrame:CGRectMake(13, height, 164, 40)];
    nameTextFiledImageView.backgroundColor = [UIColor clearColor];
    nameTextFiledImageView.userInteractionEnabled = YES;
    [nameTextFiledImageView setImage:textFiledImage];
    
    
    _nameTextField = [[UITextField alloc]initWithFrame:CGRectMake(16, 12, 140, 16)];
    _nameTextField.backgroundColor = [UIColor clearColor];
    _nameTextField.delegate = self;
    _nameTextField.textColor = [UIColor colorWithHex:0xff4a4a4a];
    _nameTextField.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    _nameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _nameTextField.placeholder = @"您贵姓";
    _nameTextField.tag = 201;
    [_nameTextField setReturnKeyType:UIReturnKeyDone];
    [nameTextFiledImageView addSubview:_nameTextField];
    [_contentView addSubview:nameTextFiledImageView];
    [nameTextFiledImageView release];
    
    UIButton *maleTextFiledImageView = [[UIButton alloc]initWithFrame:CGRectMake(195, height, 111, 40)];
    maleTextFiledImageView.backgroundColor = [UIColor clearColor];
    [maleTextFiledImageView setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kOrderForm3ImageFile ofType:nil]] forState:UIControlStateNormal];
    [maleTextFiledImageView addTarget:self action:@selector(maleTextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    _maleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 13, 100, 14)];
    _maleLabel.backgroundColor = [UIColor clearColor];
    _maleLabel.textColor = [UIColor colorWithHex:0xff505050];
    _maleLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _maleLabel.textAlignment = UITextAlignmentCenter;
    _maleLabel.text = @"男士";
    [maleTextFiledImageView addSubview:_maleLabel];
    [_contentView addSubview:maleTextFiledImageView];
    [maleTextFiledImageView release];
    
    height +=40;
    
    _malePickerBGView = [[UIView alloc]initWithFrame:CGRectMake(0, UIScreenHeight-64-190, 320, 190)];
    _malePickerBGView.backgroundColor = [UIColor whiteColor];
    [self.viewContainer addSubview:_malePickerBGView];
    
    _malePickerUpperButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, UIScreenHeight-64-190)];
    _malePickerUpperButton.backgroundColor = [UIColor clearColor];
    [_malePickerUpperButton addTarget:self action:@selector(malePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    _malePickerUpperButton.hidden = YES;
    [self.viewContainer addSubview:_malePickerUpperButton];
    
    _malePickerButtonBGView = [[UIImageView alloc]initWithFrame:kDatePickerButtonBGFrame];
    [_malePickerButtonBGView setImage:[UIImage imageNamed:kDatePickerBGImageFile]];
    _malePickerButtonBGView.userInteractionEnabled = YES;
    [_malePickerBGView addSubview:_malePickerButtonBGView];
    
    _malePickerCancelButton = [[UIButton alloc]initWithFrame:kDatePickerCancelFrame];
    [_malePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelButton] forState:UIControlStateNormal];
    [_malePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelPressed] forState:UIControlStateSelected];
    [_malePickerCancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [_malePickerCancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _malePickerCancelButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_malePickerCancelButton addTarget:self action:@selector(malePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_malePickerButtonBGView addSubview:_malePickerCancelButton];
    
    
    _malePickerDoneButton = [[UIButton alloc]initWithFrame:kDatePickerDoneFrame];
    [_malePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDoneButton] forState:UIControlStateNormal];
    [_malePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDonePressed] forState:UIControlStateSelected];
    [_malePickerDoneButton setTitle:@"完成" forState:UIControlStateNormal];
    [_malePickerDoneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _malePickerDoneButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_malePickerDoneButton addTarget:self action:@selector(malePickerDoneButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_malePickerButtonBGView addSubview:_malePickerDoneButton];
    _malePickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, 320, 150)];
    _malePickerView.tag = 101;
    _malePickerView.delegate = self;
    _malePickerView.dataSource = self;
    _malePickerView.showsSelectionIndicator = YES;
    [_malePickerBGView addSubview:_malePickerView];
    _malePickerBGView.hidden = YES;
    
    
    height +=11;
    UIImageView *phoneTextFiledImageView = [[UIImageView alloc]initWithFrame:CGRectMake(13, height, 293, 40)];
    phoneTextFiledImageView.backgroundColor = [UIColor clearColor];
    phoneTextFiledImageView.userInteractionEnabled = YES;
    [phoneTextFiledImageView setImage:textFiledImage];
    
    
    _phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(16, 12, 150, 16)];
    _phoneTextField.backgroundColor = [UIColor clearColor];
    _phoneTextField.delegate = self;
    _phoneTextField.textColor = [UIColor colorWithHex:0xff4a4a4a];
    _phoneTextField.font = [UIFont fontWithName:kFontNameHelvetica size:16];
    _phoneTextField.textAlignment = UITextAlignmentLeft;
    _phoneTextField.tag = 202;
    _phoneTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _phoneTextField.placeholder = @"联系电话";
    [_phoneTextField setReturnKeyType:UIReturnKeyDone];
    [phoneTextFiledImageView addSubview:_phoneTextField];
    [_contentView addSubview:phoneTextFiledImageView];
    [phoneTextFiledImageView release];
    height +=40;
    
    height +=11;
    UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, height+20, 70, 16)];
    messageLabel.backgroundColor = [UIColor clearColor];
    messageLabel.textColor = [UIColor colorWithHex:0xff505050];
    messageLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    messageLabel.text = @"留言";
    [_contentView addSubview:messageLabel];
    [messageLabel release];
    
    
    UIImageView *messageTextFiledImageView = [[UIImageView alloc]initWithFrame:CGRectMake(55, height, 241, 56)];
    messageTextFiledImageView.backgroundColor = [UIColor clearColor];
    messageTextFiledImageView.userInteractionEnabled = YES;
    [messageTextFiledImageView setImage:textFiledImage];
    
    
    _messageTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 240, 56)];
    _messageTextView.backgroundColor = [UIColor clearColor];
    _messageTextView.delegate = self;
    _messageTextView.textColor = [UIColor colorWithHex:0xff4a4a4a];
    _messageTextView.font = [UIFont fontWithName:kFontNameHelvetica size:16];
    _messageTextView.textAlignment = UITextAlignmentLeft;
    [_messageTextView setReturnKeyType:UIReturnKeyDone];
    [messageTextFiledImageView addSubview:_messageTextView];
    [_contentView addSubview:messageTextFiledImageView];
    [messageTextFiledImageView release];
    height +=56;
    
    height +=19;
    _commitButton = [[UIButton alloc]initWithFrame:CGRectMake(13, height, 293, 35)];
    _commitButton.backgroundColor = [UIColor clearColor];
    [_commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kButtonImageFile ofType:nil]] forState:UIControlStateNormal];
    [_commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kButtonImageFile ofType:nil]] forState:UIControlStateHighlighted];
    _commitButton.titleLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    [_commitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_commitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [_commitButton setTitle:@"提交" forState:UIControlStateNormal];
    [_commitButton setTitle:@"提交" forState:UIControlStateHighlighted];
    [_commitButton addTarget:self action:@selector(commitButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_contentView addSubview:_commitButton];
    
    _contentView.contentSize = CGSizeMake(320, CGRectGetMaxY(_commitButton.frame)+19);
    
    [self.viewContainer addSubview:_contentView];
    
    
    //弹出的datepicker层
    _datePickerBGView = [[UIView alloc]initWithFrame:kDatePickerBGFrame];
    _datePickerBGView.backgroundColor = [UIColor whiteColor];
    [self.viewContainer addSubview:_datePickerBGView];
    _datePickerUpperButton = [[UIButton alloc]initWithFrame:kDatePickerUpperFrame];
    _datePickerUpperButton.backgroundColor = [UIColor clearColor];
    [_datePickerUpperButton addTarget:self action:@selector(datePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    _datePickerUpperButton.hidden = YES;
    [self.viewContainer addSubview:_datePickerUpperButton];
    _datePickerButtonBGView = [[UIImageView alloc]initWithFrame:kDatePickerButtonBGFrame];
    [_datePickerButtonBGView setImage:[UIImage imageNamed:kDatePickerBGImageFile]];
    _datePickerButtonBGView.userInteractionEnabled = YES;
    [_datePickerBGView addSubview:_datePickerButtonBGView];
    _datePickerCancelButton = [[UIButton alloc]initWithFrame:kDatePickerCancelFrame];
    [_datePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelButton] forState:UIControlStateNormal];
    [_datePickerCancelButton setBackgroundImage:[UIImage imageNamed:kDatePickerCancelPressed] forState:UIControlStateSelected];
    [_datePickerCancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [_datePickerCancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _datePickerCancelButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_datePickerCancelButton addTarget:self action:@selector(datePickerCalcelButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_datePickerButtonBGView addSubview:_datePickerCancelButton];
    
    _datePickerDoneButton = [[UIButton alloc]initWithFrame:kDatePickerDoneFrame];
    [_datePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDoneButton] forState:UIControlStateNormal];
    [_datePickerDoneButton setBackgroundImage:[UIImage imageNamed:kDatePickerDonePressed] forState:UIControlStateSelected];
    [_datePickerDoneButton setTitle:@"完成" forState:UIControlStateNormal];
    [_datePickerDoneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _datePickerDoneButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [_datePickerDoneButton addTarget:self action:@selector(datePickerDoneButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_datePickerButtonBGView addSubview:_datePickerDoneButton];
    _datePicker = [[UIDatePicker alloc]initWithFrame:kDatePickerFrame];
    _datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    _datePicker.minimumDate = [NSDate date];
    _datePicker.minuteInterval = 5;
    NSDate *date = [NSDate date];
    [_datePicker setDate:date];
    [_datePickerBGView addSubview:_datePicker];
    _datePickerBGView.hidden = YES;
}


-(NSString *)getWeekDayStringWithNumber:(NSInteger)weekNumber{
    switch (weekNumber) {
        case 1:
            return @"星期天";
            break;
        case 2:
            return @"星期一";
            break;
        case 3:
            return @"星期二";
            break;
        case 4:
            return @"星期三";
            break;
        case 5:
            return @"星期四";
            break;
        case 6:
            return @"星期五";
            break;
        case 7:
            return @"星期六";
            break;
        default:
            return @"星期天";
            break;
    }
}

#pragma mark- datePicker event
- (void) dateTextButtonClicked:(id)sender{
    
    UIButton *button = (UIButton *)sender;
    if (_datePickerBGView.hidden == NO) {
        _datePickerBGView.hidden = YES;
        
    }else{
        _datePickerBGView.hidden = NO;
        [self.viewContainer bringSubviewToFront:_datePickerBGView];
        _datePickerUpperButton.hidden = NO;
        [self.viewContainer bringSubviewToFront:_datePickerUpperButton];
        
        CGFloat buttonOriginY = CGRectGetMaxY(button.frame);
        CGFloat bgViewOriginY = _datePickerBGView.frame.origin.y;
        
        CGFloat contentOffset = _contentView.contentOffset.y;
        self.currentContentOffsetY = contentOffset;
        
        if (buttonOriginY+5-contentOffset > bgViewOriginY) {
            _contentView.contentOffset = CGPointMake(0, (buttonOriginY+5-bgViewOriginY));
        }
        
    }
}

- (void)datePickerCalcelButtonClicked{
    _datePickerBGView.hidden = YES;
    _datePickerUpperButton.hidden = YES;
    _commitButton.hidden = NO;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
}

- (void)datePickerDoneButtonClicked{
    NSDate *date = _datePicker.date;
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString = [formatter stringFromDate:date];
    [formatter setDateFormat:@"HH:mm"];
    NSString *timeString = [formatter stringFromDate:date];
    [formatter release];
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *currentComponent = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSCalendarCalendarUnit| NSWeekOfMonthCalendarUnit fromDate:date];
    NSString *weekString = [self getWeekDayStringWithNumber:[currentComponent weekday]];
    
    _dateLabel.text = [NSString stringWithFormat:@"%@  %@",dateString,weekString];
    _timeLabel.text = timeString;
    _datePickerBGView.hidden = YES;
    _datePickerUpperButton.hidden = YES;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
    
}

#pragma -mark UITextFeildDelegate

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if ([string isEqualToString:@"\n"]) {
        [textField resignFirstResponder];
        return NO;
    }
    return YES;
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if (textField.tag == 201) {
        self.textViewType = TextViewTypeName;
    }else{
        self.textViewType = TextViewTypePhone;
    }
    return YES;
}

#pragma -mark UITextViewDelegate

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    self.textViewType = TextViewTypeMessage;
    return YES;
}

#pragma UIPickerViewDelegate

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (pickerView.tag == 101) {
        return [_maleArray count];
    }else if(pickerView.tag == 102){
        return [_peopleNumberArray count];
    }else{
        return (self.orderInfoDataModel != nil && self.orderInfoDataModel.typeArray != nil) ? [self.orderInfoDataModel.typeArray count] : 0;
    }
    
}
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (pickerView.tag == 101) {
        NSString *str = nil;
        str = [_maleArray safeObjectAtIndex:row];
        if (nil == str) {
            str = @"";
        }
        return str;
    }else if(pickerView.tag == 102){
        NSString *str = nil;
        str = [_peopleNumberArray safeObjectAtIndex:row];
        if (nil == str) {
            str = @"";
        }
        return str;
    }else{
        NSString *str = nil;
        if (self.orderInfoDataModel && self.orderInfoDataModel.typeArray) {
            str = [self.orderInfoDataModel.typeArray safeObjectAtIndex:row];
            if (nil == str) {
                str = @"";
            }
            return str;
        }
        return nil;
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (pickerView.tag == 101) {
        NSString *str = nil;
        str = [_maleArray safeObjectAtIndex:row];
        if (nil == str) {
            str = @"";
        }
        self.maleString = str;
    }else if(pickerView.tag == 102){
        NSString *str = nil;
        str = [_peopleNumberArray safeObjectAtIndex:row];
        if (nil == str) {
            str = @"";
        }
        self.peopleString = str;
    }else{
        NSString *str = nil;
        if (self.orderInfoDataModel && self.orderInfoDataModel.typeArray) {
            str = [self.orderInfoDataModel.typeArray safeObjectAtIndex:row];
            if (nil == str) {
                str = @"";
            }
            self.typeString = str;
        }
        
    }
}


#pragma mark- malePicker event
- (void) maleTextButtonClicked:(id)sender{
    
    UIButton *button = (UIButton *)sender;
    
    if (_malePickerBGView.hidden == NO) {
        _malePickerBGView.hidden = YES;
        
    }else{
        _malePickerBGView.hidden = NO;
        [self.viewContainer bringSubviewToFront:_malePickerBGView];
        _malePickerUpperButton.hidden = NO;
        [self.viewContainer bringSubviewToFront:_malePickerUpperButton];
        
        CGFloat buttonOriginY = CGRectGetMaxY(button.frame);
        CGFloat bgViewOriginY = _malePickerBGView.frame.origin.y;
        
        CGFloat contentOffset = _contentView.contentOffset.y;
        self.currentContentOffsetY = contentOffset;
        
        if (buttonOriginY+5-contentOffset > bgViewOriginY) {
            _contentView.contentOffset = CGPointMake(0, (buttonOriginY+5-bgViewOriginY));
        }
        
    }
}

- (void)malePickerCalcelButtonClicked{
    _malePickerBGView.hidden = YES;
    _malePickerUpperButton.hidden = YES;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
}

- (void)malePickerDoneButtonClicked{
    
    _maleLabel.text = self.maleString;
    _malePickerBGView.hidden = YES;
    _malePickerUpperButton.hidden = YES;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
    
}


#pragma mark- peoplePicker event
- (void) peopleTextButtonClicked:(id)sender{
    
    UIButton *button = (UIButton *)sender;
    
    if (_peoplePickerBGView.hidden == NO) {
        _peoplePickerBGView.hidden = YES;
        
    }else{
        _peoplePickerBGView.hidden = NO;
        [self.viewContainer bringSubviewToFront:_peoplePickerBGView];
        _peoplePickerUpperButton.hidden = NO;
        [self.viewContainer bringSubviewToFront:_peoplePickerUpperButton];
        
        CGFloat buttonOriginY = CGRectGetMaxY(button.frame);
        CGFloat bgViewOriginY = _peoplePickerBGView.frame.origin.y;
        
        CGFloat contentOffset = _contentView.contentOffset.y;
        self.currentContentOffsetY = contentOffset;
        
        if (buttonOriginY+5-contentOffset > bgViewOriginY) {
            _contentView.contentOffset = CGPointMake(0, (buttonOriginY+5-bgViewOriginY));
        }
        
    }
}

- (void)peoplePickerCalcelButtonClicked{
    _peoplePickerBGView.hidden = YES;
    _peoplePickerUpperButton.hidden = YES;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
}

- (void)peoplePickerDoneButtonClicked{
    
    _peopleNumberLabel.text = self.peopleString;
    _peoplePickerBGView.hidden = YES;
    _peoplePickerUpperButton.hidden = YES;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
    
}

#pragma mark- peoplePicker event
- (void) typeTextButtonClicked:(id)sender{
    
    UIButton *button = (UIButton *)sender;
    
    if (_typePickerBGView.hidden == NO) {
        _typePickerBGView.hidden = YES;
        
    }else{
        _typePickerBGView.hidden = NO;
        [self.viewContainer bringSubviewToFront:_typePickerBGView];
        _typePickerUpperButton.hidden = NO;
        [self.viewContainer bringSubviewToFront:_typePickerUpperButton];
        
        CGFloat buttonOriginY = CGRectGetMaxY(button.frame);
        CGFloat bgViewOriginY = _typePickerBGView.frame.origin.y;
        
        CGFloat contentOffset = _contentView.contentOffset.y;
        self.currentContentOffsetY = contentOffset;
        
        if (buttonOriginY+5-contentOffset > bgViewOriginY) {
            _contentView.contentOffset = CGPointMake(0, (buttonOriginY+5-bgViewOriginY));
        }
        
    }
}

- (void)typePickerCalcelButtonClicked{
    _typePickerBGView.hidden = YES;
    _typePickerUpperButton.hidden = YES;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
}

- (void)typePickerDoneButtonClicked{
    
    _typeLabel.text = self.typeString;
    _typePickerBGView.hidden = YES;
    _typePickerUpperButton.hidden = YES;
    _contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
    
}


-(void)commitButtonClicked{
    
    _commitButton.enabled = NO;
    
    NetworkStatus status = [GloableEngineService sharedInstance].netWorkStatus;
    if (status == kNotReachable) {
        [RCAppDelegate alertWithNetworkError];
        _commitButton.enabled = YES;
        return;
    }
    if (nil == _nameTextField.text ||[_nameTextField.text isEqualToString:@""] || [_nameTextField.text isEqualToString:@"您贵姓"]) {
        [RCAppDelegate alertWithCustomizeString:@"请填写您贵姓！"];
        _commitButton.enabled = YES;
        return;
    }
    
    if (nil == _phoneTextField.text ||[_phoneTextField.text isEqualToString:@""] || [_phoneTextField.text isEqualToString:@"联系电话"]) {
        [RCAppDelegate alertWithCustomizeString:@"请填写联系电话！"];
        _commitButton.enabled = YES;
        return;
    }
    
    NSString *phone = _phoneTextField.text;
    
    NSError * error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^1[34578]\\d{9}$" options:0 error:&error];
    NSTextCheckingResult * result = [regex firstMatchInString:phone options:0 range:NSMakeRange(0, [phone length])];
    if (!result || (regex.numberOfCaptureGroups + 1) != result.numberOfRanges) {
        [RCAppDelegate alertWithCustomizeString:@"手机号码输入格式错误哦！"];
        _commitButton.enabled = YES;
        return;
    }
    
    NSString *content = _messageTextView.text;
    
    NSString *name = _nameTextField.text;
    
    NSString *date = _dateLabel.text;
    NSString *time = _timeLabel.text;
    NSString *num = _peopleNumberLabel.text;
    NSString *type = @"";
    if (self.orderInfoDataModel.typeArray != nil && [self.orderInfoDataModel.typeArray count] > 0) {
        type = _typeLabel.text;
    }
    
    NSString *sex = nil;
    if ([_maleLabel.text isEqualToString:@"男士"]) {
        sex = @"1";
    }else{
        sex = @"2";
    }
    
    
    _progressHub = [[MBProgressHUDEx alloc] initWithView:self.view
                                               TopHeight:0
                                        withBottomHeight:0
                                           withLeftWidth:0
                                          withRightWidth:0
                                    withExclusiveObjects:nil];
    _progressHub.delegate = self;
    _progressHub.labelText = @"提交中...";
    [self.view addSubview:_progressHub];
    [self.view bringSubviewToFront:_progressHub];
    [_progressHub show:YES];
    _requestID = [[IManager sharedInstance]requestCommitOrder:self.shopID withName:name withContent:content withPhone:phone withDate:date withTime:time withPeopleNum:num withType:type withSex:sex withDelegate:self];

}

-(void)updateViewForSuccess:(IDataModel *)dataModel withRequestId:(int64_t)requestId{
    if (_requestID == requestId) {
        [_progressHub removeFromSuperview];
        [_progressHub release];
        _progressHub = nil;
        RCFeedbackDataModel *feedbackDataModel = (RCFeedbackDataModel *)dataModel;
        if (feedbackDataModel.errorNO == 0) {
            [RCAppDelegate alertWithCustomizeString:@"提交成功"];
            _commitButton.enabled = NO;
            [self performSelector: @selector(leftButtonClicked) withObject: nil afterDelay: 1.5f];
        }else{
            [RCAppDelegate alertWithCustomizeString:@"提交失败，请稍后重试"];
            _commitButton.enabled = YES;
        }
    }else if (_orderInfoRequestID == requestId){
        [_progressHub removeFromSuperview];
        [_progressHub release];
        _progressHub = nil;
        self.orderInfoDataModel = (RCMerchantOrderDataModel *)dataModel;
        [self customizeView];
    }
}

-(void)leftButtonClicked{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)updateViewForError:(NSError *)errorInfo withRequestId:(int64_t)requestId{
    if (_requestID == requestId) {
        [_progressHub removeFromSuperview];
        [_progressHub release];
        _progressHub = nil;
        [RCAppDelegate alertWithCustomizeString:@"提交失败，请稍后重试"];
        _commitButton.enabled = YES;
    }else if (_orderInfoRequestID == requestId){
        [_progressHub removeFromSuperview];
        [_progressHub release];
        _progressHub = nil;
    }
}

#pragma mark -
#pragma mark Responding to keyboard events
- (void)keyboardWillShow:(NSNotification *)notification {
    
    NSDictionary *userInfo = [notification userInfo];
    NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [value CGRectValue];
    
    CGFloat keyboardOriginY = UIScreenHeight-64-keyboardRect.size.height;
    
    CGFloat textMaxY = 0;
    switch (self.textViewType) {
        case TextViewTypePhone:
            textMaxY = CGRectGetMaxY(_phoneTextField.superview.frame);
            break;
         case TextViewTypeName:
            textMaxY = CGRectGetMaxY(_nameTextField.superview.frame);
            break;
        case TextViewTypeMessage:
            textMaxY = CGRectGetMaxY(_messageTextView.superview.frame);
        default:
            break;
    }
    
    CGFloat contentOffsetY = self.contentView.contentOffset.y;
    
    if (textMaxY + 5 - contentOffsetY > keyboardOriginY) {
        self.currentContentOffsetY = contentOffsetY;
        
        [UIView animateWithDuration:0.3f animations:^{
            CGFloat heightReduce = abs(textMaxY +5 - keyboardOriginY);
            self.contentView.contentOffset = CGPointMake(0, heightReduce);
        }];
        
    }
    
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    [UIView animateWithDuration:0.3f animations:^{
        self.contentView.contentOffset = CGPointMake(0, self.currentContentOffsetY);
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
